"""
    获取驱动对象，驱动对象类
"""
from selenium import webdriver
from selenium.webdriver.chrome.service import Service


class DriverUtils:
    # 私有的外卖管理端驱动对象
    __admin_driver = None
    __admin_key = None
    # 修改关闭驱动对象开关值的方法
    @classmethod
    def change_admin_key(cls, key):
        cls.__admin_key = key

    # 获取外卖管理端驱动对象
    @classmethod
    def get_admin_driver(cls):
        # 判断管理端驱动对象是否为空，为空则创建
        if cls.__admin_driver is None:
            service = Service('D:/ChromeDriver/chromedriver.exe')
            cls.__admin_driver = webdriver.Chrome(service=service)
            # 最大化窗口
            cls.__admin_driver.maximize_window()
            # 隐式等待
            # cls.__admin_driver.implicitly_wait(30)
        return cls.__admin_driver


    # 关闭外卖管理端驱动对象
    @classmethod
    def close_admin_driver(cls):
        # 判断管理端商家驱动对象是否不为空
        if cls.__admin_driver is not None and cls.__admin_key:
            # 关闭驱动对象
            cls.__admin_driver.close()
            # 置null
            cls.__admin_driver = None

